<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="https://cdn.bootcss.com/jquery/2.1.2/jquery.min.js"></script>
    <script>
        $(function () {

            $("#subbtn").click(function () {

                var flag = true;

                $("#err_username").html('');
                $("#err_userpasswd").html('');

                var username = $("input[name='username']").val();
                var userpasswd = $("input[name='userpasswd']").val();

                if(username == ''){
                    $("#err_username").html('提示：用户名不能为空！');
                   // $("input[name='username']").focus();
                    flag = false;
                }

                if(userpasswd == '') {
                    $("#err_userpasswd").html('提示：密码不能为空！');
                   // $("input[name='userpasswd']").focus();
                    flag = false;
                }

                if(flag){

                    $.post('checkLogin.php',{username:username, userpasswd:userpasswd}, function (data) {

                        if (data.code == 200){
                            window.location.href='list.php';
                            return;
                        } else if(data.code == 201){
                            $("#err_username").html(data.message);
                            return;
                        } else  if(data.code == 202){
                            $("#err_userpasswd").html(data.message);
                            return;
                        }

                    }, 'json');
                }


            });

        });
    </script>
    <title>博客</title>
    <style>
        #login{
            width: 550px;
            height: auto;
            overflow: hidden;
            margin:0 auto;
            margin-top: 100px;
        }
        input.in{
            width: 280px;
            height: 18px;
            padding: 2px 10px;
            border: 1px solid #b9b9b9;
        }
        a.subbtn{
            color: #000000;
            text-decoration: none;
            border: 1px solid #484848;
            width: 65px;
            height: 24px;
            line-height: 24px;
            overflow: hidden;
            display: block;
            text-align: center;
        }
        label.error{
            font-size: 12px;
            color: #f00;
        }
    </style>
</head>
<body background="./blog/images/footside.jpg">

<?php

//if ($_GET['act'] == "loging"){

//    echo $_POST['username'].$_POST['userpasswd'].'<br>';
//}

?>


<div id="login">

    <form name="login" action="index.php?act=loging" method="post">

        <p>
            用户名：<input type="text" name="username" id="username" class="in">
            <label class="error" id="err_username"></label>
        </p>

        <p>
            密&nbsp;&nbsp;码：<input type="password" name="userpasswd" id="userpasswd" class="in">
            <label class="error" id="err_userpasswd"></label>
        </p>


        <a href="javascript:void(0);" id="subbtn" class="subbtn">登录</a>
    </form>
</div>

</body>
</html>